package prv.pursuivant.config.impl;

import prv.pursuivant.config.CategorySerializer;
import prv.pursuivant.core.AchievType;
import prv.pursuivant.core.AchievTypesTreeImpl;
import prv.pursuivant.core.impl.AbstractAchievType;
import prv.pursuivant.core.impl.CategoryAchievType;
import prv.pursuivant.core.impl.MetaAchievType;
import prv.pursuivant.core.impl.NormalAchievType;
import prv.pursuivant.core.impl.NpcAchievType;
import prv.pursuivant.core.impl.SubcategoryAchievType;

import com.google.inject.AbstractModule;
import com.google.inject.Provides;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;

/**
 * Factory class to instantiate XStream serializers
 * 
 * @author Kwinto
 */
public class XStreamCategorySerializerModule extends AbstractModule {

	@Provides
	XStream provideXStream() {
		XStream xstream = new XStream(new DomDriver());
		xstream.alias("category", CategoryAchievType.class);
		xstream.alias("tree", AchievTypesTreeImpl.class);
		xstream.alias("root", AchievType.class, CategoryAchievType.class);
		xstream.alias("achievement", NormalAchievType.class);
		xstream.alias("npc", NpcAchievType.class);
		xstream.alias("subcategory", SubcategoryAchievType.class);
		xstream.alias("meta", MetaAchievType.class);
		xstream.addImplicitCollection(AbstractAchievType.class, "criteria",
				"criteria", String.class);
		xstream.omitField(CategoryAchievType.class, "cacheMap");
		xstream.useAttributeFor(String.class);
		xstream.useAttributeFor(Integer.class);
		xstream.useAttributeFor(Boolean.class);
		return xstream;
	}

	@Override
	protected void configure() {
		bind(CategorySerializer.class).to(XStreamCategorySerializer.class);
	}

}
